package com.service.impl;

import com.bean.entity.Provice;
import com.bean.pojo.PageAssistant;
import com.dao.ProviceMapper;
import com.service.ProviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:11
 */
@Service
public class ProviceServiceImpl implements ProviceService {

    @Autowired
    private ProviceMapper proviceMapper;
    @Override
    public int save(Provice t) throws Exception {
        int insert = proviceMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增省份信息失败");
    }
    @Override
    public int remove(Provice t) throws Exception {
        int delete = proviceMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除省份信息失败");
    }
    @Override
    public int modify(Provice t) throws Exception {
        int update = proviceMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改省份信息失败");
    }
    @Override
    public Provice unique(Provice t) throws Exception {
        List<Provice> proviceList = proviceMapper.select(t);
        if (proviceList.size() !=1) throw new Exception("无此省份信息");
        return proviceList.get(0);
    }
    @Override
    public List<Provice> query(Provice t) {
        List<Provice> proviceList = proviceMapper.select(t);
        return proviceList;
    }
    @Override
    public PageAssistant<Provice> queryByPage(Map<String, Object> map, PageAssistant<Provice> pa) {

        //查询并设置总记录数
        pa.setCount(proviceMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(proviceMapper.selectByPage(map));
        return pa;
    }
}
